﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using Com_Orion_Test_DLL;

namespace Com_Orion_Test_Tool
{
    public partial class Form1 : Form
    {
        private List<TextBox> PGPATHBoxLst;
        private List<TextBox> ArgBoxLst;
        private List<Button> RunBtnLst;
        private List<Button> LogBtnLst;
        private xmlCtrl XMLCTRL;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            init();
        }
        private void init()
        {
            XMLCTRL = new xmlCtrl();
            ExesetLst();
            ExeparmSet();
            LogsetLst();
        }
        private void ExesetLst()
        {
            PGPATHBoxLst = new List<TextBox>();
            ArgBoxLst = new List<TextBox>();
            RunBtnLst = new List<Button>();
            PGPATHBoxLst.Add(Exe_Box1);
            PGPATHBoxLst.Add(Exe_Box2);
            PGPATHBoxLst.Add(Exe_Box3);
            PGPATHBoxLst.Add(Exe_Box4);
            ArgBoxLst.Add(Arg_Box1);
            ArgBoxLst.Add(Arg_Box2);
            ArgBoxLst.Add(Arg_Box3);
            ArgBoxLst.Add(Arg_Box4);
            RunBtnLst.Add(Run_Btn1);
            RunBtnLst.Add(Run_Btn2);
            RunBtnLst.Add(Run_Btn3);
            RunBtnLst.Add(Run_Btn4);
        }
        private void ExeparmSet()
        {
            for (int i = 0; i < PGPATHBoxLst.Count(); i++)
            {
                PGPATHBoxLst[i].Text = XMLCTRL.ArrayTP[i].ProgramFullPath.ToString().Trim('\"');
                ArgBoxLst[i].Text = XMLCTRL.ArrayTP[i].ProgramArg.ToString().Trim('\"'); ;
                RunBtnLst[i].Text = XMLCTRL.ArrayTP[i].ProgramName.ToString().Trim('\"'); ;
            }
        }
        private void ExeSetAndRun(int num)
        {
            XMLCTRL.ArrayTP[num].ProgramArg = ArgBoxLst[num].Text;
            XMLCTRL.ArrayTP[num].ProgramFullPath = PGPATHBoxLst[num].Text;
            XMLCTRL.ArrayTP[num].Run();
        }
        private void LogsetLst()
        {
            LogBtnLst = new List<Button>();
            LogBtnLst.Add(Log_Btn1);
            LogBtnLst.Add(Log_Btn2);
            LogBtnLst.Add(Log_Btn3);
            LogBtnLst.Add(Log_Btn4);
            LogBtnLst.Add(Log_Btn5);
            LogBtnLst.Add(Log_Btn6);
            LogBtnLst.Add(Log_Btn7);
            for (int i = 0; i < LogBtnLst.Count(); i++)
            {
                LogBtnLst[i].Text = XMLCTRL.ArrayLog[i].LogName.ToString();
            }
        }
        private void Run_Btn1_Click(object sender, EventArgs e)
        {
            ExeSetAndRun(0);
        }

        private void Run_Btn2_Click(object sender, EventArgs e)
        {
            ExeSetAndRun(1);
        }

        private void Run_Btn3_Click(object sender, EventArgs e)
        {
            ExeSetAndRun(2);
        }

        private void Run_Btn4_Click(object sender, EventArgs e)
        {
            ExeSetAndRun(3);
        }

        private void Log_Btn1_Click(object sender, EventArgs e)
        {
            XMLCTRL.ArrayLog[0].Open();
        }

        private void Log_Btn2_Click(object sender, EventArgs e)
        {
            XMLCTRL.ArrayLog[1].Open();
        }

        private void Log_Btn3_Click(object sender, EventArgs e)
        {
            XMLCTRL.ArrayLog[2].Open();
        }

        private void Log_Btn4_Click(object sender, EventArgs e)
        {
            XMLCTRL.ArrayLog[3].Open();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.init();
        }

        private void Log_Btn5_Click(object sender, EventArgs e)
        {
            XMLCTRL.ArrayLog[4].Open();
        }

        private void Log_Btn6_Click(object sender, EventArgs e)
        {
            XMLCTRL.ArrayLog[5].Open();
        }

        private void Log_Btn7_Click(object sender, EventArgs e)
        {
            XMLCTRL.ArrayLog[6].Open();
        }

        private void XmlWriteBtn_Click(object sender, EventArgs e)
        {
            for (int num = 0; num < PGPATHBoxLst.Count(); num++)
            {
                XMLCTRL.ArrayTP[num].ProgramArg = ArgBoxLst[num].Text;
                XMLCTRL.ArrayTP[num].ProgramFullPath = PGPATHBoxLst[num].Text;
            }
            XMLCTRL.FileWrite();
        }

        
    }
}
